package RadianceM.DistributionSystem.voto.result;

import lombok.Data;
import lombok.ToString;

/**
 * 统一API对象返回
 * @param <T>
 * @Author: 小碗
 * @Date: 2023/11/3 13:42:33
 */

@Data
@ToString
public class DSResult<T> {

	/** 状态码 */
	private Integer code;

	/** 返回消息 */
	private String message;

	/** 状态 */
	private boolean status;

	/** 返回数据 */
	private T data;

	public DSResult(Integer code, String message, boolean status, T data) {
		this.code = code;
		this.message = message;
		this.status = status;
		this.data = data;
	}

	public DSResult(ResultCode resultCode, boolean status, T data) {
		this.code = resultCode.getCode();
		this.message = resultCode.getMessage();
		this.status = status;
		this.data = data;
	}

	public DSResult(ResultCode resultCode, boolean status) {
		this.code = resultCode.getCode();
		this.message = resultCode.getMessage();
		this.status = status;
		this.data = null;
	}

	public static <T> DSResult<T> success() {
		return new DSResult<>(ResultCode.SUCCESS, true);
	}

	public static <T> DSResult<T> message(String message) {
		return new DSResult<>(ResultCode.SUCCESS.getCode(), message, true, null);
	}

	public static <T> DSResult<T> success(T data) {
		return new DSResult<>(ResultCode.SUCCESS, true, data);
	}

	public static <T> DSResult<T> success(String message,T data) {
		return new DSResult<>(ResultCode.SUCCESS.getCode(), message, true, data);
	}

	public static <T> DSResult<T> fail() {
		return new DSResult<>(ResultCode.ERROR, false);
	}

	public static <T> DSResult<T> fail(ResultCode resultCode) {
		return new DSResult<>(resultCode, false);
	}

	public static <T> DSResult<T> fail(Integer code, String message) {
		return new DSResult<>(code, message, false, null);
	}

	public static <T> DSResult<T> fail(ResultCode resultCode, T data) {
		return new DSResult<>(resultCode, false, data);
	}

	public static <T> DSResult<T> fail(Integer code, String message, T data) {
		return new DSResult<>(code, message, false, data);
	}
}
